﻿

namespace Common.Algorithm.Core.LocalTest;

#region   function and decode 

public class TargetFunc1D : ITargetFunction
{
    public int sequenceLen { get; set; } = 32;
    public IList<double[]> ranges { get; set; } = new List<double[]>() {
            new double[] {  -50d, 50d },
        };
    public Func<double[], double> GenMathFunction()
    {
        Func<double[], double> func = (pnt) =>
        {
            var x = pnt[0];
            //double res = Math.Abs((x - 5d) / (2 * Math.Sin(x)));
            double res = 3d * (x - 15d) * (x - 15d);
            return res;
        };
        return func;
    }

    public double[] BinaryDecode(int[] values)
    {
        List<int> xBins = values.ToList().GetRange(0, 16);
        var xBin = Convert.ToInt16(string.Join("", xBins), 2);
        double[] doubles = new double[1] { ranges[0][0] +
                xBin * (ranges[0][1]- ranges[0][0]) / 65534d };
        //double[] doubles = new double[1] { xBin };
        return doubles;
    }
}

 

#endregion
